home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu358.dms / pu358.adf / DonsGenies / Don'sGenies / BordersSimpleShapes.pprx < prev    next >
Text File  |  1992-08-08  |  27KB  |  823 lines

  1. /* This Genie puts a decorative border around a box, using data stored in the genie. The resulting border is merged into a single box. The current line and fill colours are used. 
  2. Genie written and © by Don Cox   July 92  */
  3.  
  4.  
  5. trace n
  6. address command
  7. signal on error
  8. signal on syntax
  9. signal on halt
  10. signal on break_c
  11. signal on break_d
  12. signal on break_e
  13.  
  14. if ~show("l", "gdarexxsupport.library") then
  15.     if ~addlib("gdarexxsupport.library", 0, -30,0) then
  16.     do
  17.         call ppm_Inform(1,"Please install the gdarexxsupport.library in your libs: directory before running this Genie.")
  18.     end
  19.  
  20. call ppm_AutoUpdate(0)
  21. call SafeEndEdit.rexx()
  22. cr="0a"x
  23.  
  24.  
  25. CurrentUnits = ppm_GetUnits()
  26.  
  27. select
  28.     when CurrentUnits = 1 then do
  29.         units="inches"
  30.         mul = 1
  31.         mul2 = 72
  32.         end
  33.     when CurrentUnits = 2 then do
  34.         units="mm"
  35.         mul = 10
  36.         mul2 = 28.4
  37.         end
  38.     otherwise do 
  39.         call ppm_SetUnits(2)
  40.         units="mm"
  41.         mul = 10
  42.         mul2 = 28.4
  43.         end
  44.     end
  45.  
  46. mainbox = ppm_ClickOnBox("  Click on box to be given a border")
  47. if mainbox = 0 then exit_msg("No box selected")
  48. mainpos = ppm_GetBoxPosition(mainbox)
  49. mainXpos = word(mainpos, 1)
  50. mainYpos = word(mainpos, 2)
  51. mainsize = ppm_GetBoxSize(mainbox)
  52. mainwidth = word(mainsize,1)
  53. mainheight = word(mainsize,2)
  54. mainangle = ppm_GetBoxAngle(mainbox)
  55.  
  56.  
  57. /* Initialize data strings  */
  58. cornerline1 = "" 
  59. cornerline2 = ""
  60. cornerline3 = ""
  61. cornerweight1 = "" 
  62. cornerweight2 = ""
  63. cornerweight3 = ""
  64. sideline1 = ""
  65. sideline2 = ""
  66. sideline3 = ""
  67. cornerXoffset = 0
  68. cornerYoffset = 0
  69. sideXoffset = 0
  70. sideYoffset = 0
  71. cornerfill1 = 0
  72. cornerfill2 = 0
  73. cornerfill3 = 0
  74. sidefill1 = 0
  75. sidefill2 = 0
  76. sidefill3 = 0
  77. lines = 1
  78.  
  79. list = "Greek Key"cr"Two Rules"cr"Two Rules Rounded"cr"Two Rules Reverse Rounded"cr"Three Rules"cr"Battlements"cr"Cutout"cr"Filled Squares"cr"Double Squares"cr"Off-Centre Squares"cr"Filled Triangles"cr"Filled Triangles 2"cr"Three Ls"cr"Bars"
  80. chosen = ppm_SelectFromList("Select Border Pattern",30,14,0,list)
  81. if chosen = "" then exit_msg("Aborted by User")
  82.  
  83. /* Data for various patterns  */
  84.  
  85. select 
  86.  
  87.     when chosen = "Bars" then do
  88.         cornerline1 = "0 0"cr"3 0"cr"3 3"cr"0 3"cr"0 0"
  89.         cornerline2 = "5 0"cr"7 0"cr"7 7"cr"0 7"cr"0 5"cr"5 5"cr"5 0"
  90.         cornerline3 = "9 0"cr"11 0"cr"11 11"cr"0 11"cr"0 9"cr"9 9"cr"9 0"
  91.         sideline1 = "1 0"cr"3 0"cr"3 12"cr"1 12"cr"1 0"
  92.         sideline2 = "5 0"cr"7 0"cr"7 12"cr"5 12"cr"5 0"
  93.         sideheight = 12
  94.         sidewidth = 8
  95.         sideXoffset = 1
  96.         sideYoffset = 0
  97.         cornerheight = 12
  98.         cornerwidth = 12
  99.         cornerXoffset = 0
  100.         cornerYoffset = 0
  101.         cornerfill1 = 1
  102.         cornerfill2 = 1
  103.         cornerfill3 = 1
  104.         sidefill1 = 1
  105.         sidefill2 = 1
  106.         sidefill3 = 0
  107.         lines = 0   /* number of line weights to be set by user  */
  108.         end
  109.  
  110.     when chosen = "Three Ls" then do
  111.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  112.         cornerline2 = "6 0"cr"9 0"cr"9 9"cr"0 9"cr"0 6"cr"6 6"cr"6 0"
  113.         sideline1 = "1 0"cr"3 0"cr"3 8"cr"11 8"cr"11 10"cr"1 10"cr"1 0"
  114.         sideline2 = "5 0"cr"7 0"cr"7 4"cr"11 4"cr"11 6"cr"5 6"cr"5 0"
  115.         sideline3 = "9 0"cr"11 0"cr"11 2"cr"9 2"cr"9 0"
  116.         sideheight = 10
  117.         sidewidth = 12
  118.         sideXoffset = 1
  119.         sideYoffset = 0
  120.         cornerheight = 10
  121.         cornerwidth = 10
  122.         cornerXoffset = 0
  123.         cornerYoffset = 0
  124.         cornerfill1 = 1
  125.         cornerfill2 = 1
  126.         sidefill1 = 1
  127.         sidefill2 = 1
  128.         sidefill3 = 1
  129.         lines = 0
  130.         end
  131.  
  132.     when chosen = "Filled Triangles 2" then do
  133.         cornerline1 = "4.3 0"cr"4.3 4.3"cr"0 4.3"cr"4.3 0"
  134.         sideline1 = "0 0"cr"4 0"cr"0 4"cr"0 0"
  135.         sideline2 = "5 1"cr"5 5"cr"1 5"cr"5 1"
  136.         sideheight = 5
  137.         sidewidth = 6.4
  138.         sideXoffset = 0.7
  139.         sideYoffset = 0
  140.         cornerheight = 5
  141.         cornerwidth = 5
  142.         cornerXoffset = 0
  143.         cornerYoffset = 0
  144.         cornerfill1 = 1
  145.         sidefill1 = 1
  146.         sidefill2 = 1
  147.         sidefill3 = 0
  148.         lines = 0
  149.         end
  150.  
  151.     when chosen = "Filled Triangles" then do
  152.         cornerline1 = "2.6 0"cr"2.6 2.6"cr"0 2.6"cr"2.6 0"
  153.         sideline1 = "0 0"cr"4 4"cr"0 4"cr"0 0"
  154.         sideline2 = "2 0"cr"10 0"cr"6 4"cr"2 0"
  155.         sideline3 = "12 0"cr"12 4"cr"8 4"cr"12 0"
  156.         sideheight = 4
  157.         sidewidth = 12
  158.         sideXoffset = 0
  159.         sideYoffset = 0
  160.         cornerheight = 4
  161.         cornerwidth = 4
  162.         cornerXoffset = 0
  163.         cornerYoffset = 0
  164.         cornerfill1 = 1
  165.         sidefill1 = 1
  166.         sidefill2 = 1
  167.         sidefill3 = 1
  168.         lines = 0
  169.         end
  170.  
  171.     when chosen = "Off-Centre Squares" then do
  172.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  173.         cornerline2 = "0 0"cr"2 0"cr"2 2"cr"0 2"cr"0 0"
  174.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  175.         sideline2 = "1 0"cr"3 0"cr"3 2"cr"1 2"cr"1 0"
  176.         sideheight = 5
  177.         sidewidth = 6
  178.         sideXoffset = 1
  179.         sideYoffset = 0
  180.         cornerheight = 5
  181.         cornerwidth = 5
  182.         cornerXoffset = 0
  183.         cornerYoffset = 0
  184.         cornerfill1 = 0
  185.         sidefill1 = 0
  186.         lines = 1
  187.         end
  188.  
  189.     when chosen = "Double Squares" then do
  190.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  191.         cornerline2 = "1 1"cr"3 1"cr"3 3"cr"1 3"cr"1 1"
  192.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  193.         sideline2 = "2 1"cr"4 1"cr"4 3"cr"2 3"cr"2 1"
  194.         sideheight = 5
  195.         sidewidth = 6
  196.         sideXoffset = 1
  197.         sideYoffset = 0
  198.         cornerheight = 5
  199.         cornerwidth = 5
  200.         cornerXoffset = 0
  201.         cornerYoffset = 0
  202.         cornerfill1 = 0
  203.         sidefill1 = 0
  204.         lines = 1
  205.         end
  206.  
  207.     when chosen = "Filled Squares" then do
  208.         cornerline1 = "0 0"cr"4 0"cr"4 4"cr"0 4"cr"0 0"
  209.         sideline1 = "1 0"cr"5 0"cr"5 4"cr"1 4"cr"1 0"
  210.         sideheight = 5
  211.         sidewidth = 6
  212.         sideXoffset = 1
  213.         sideYoffset = 0
  214.         cornerheight = 5
  215.         cornerwidth = 5
  216.         cornerXoffset = 0
  217.         cornerYoffset = 0
  218.         cornerfill1 = 1
  219.         sidefill1 = 1
  220.         lines = 0
  221.         end
  222.  
  223.     when chosen = "Cutout" then do
  224.         cornerline1 = "0 1"cr"0 0"cr"1 0"
  225.         sideline1 = "0 0"cr"1 0"
  226.         sideline2 = "3 0"cr"4 0"
  227.         sideheight = 1
  228.         sidewidth = 4
  229.         sideXoffset = 0
  230.         sideYoffset = 0
  231.         cornerheight = 1
  232.         cornerwidth = 1
  233.         cornerXoffset = 0
  234.         cornerYoffset = 0
  235.         lines = 1
  236.         end
  237.  
  238.     when chosen = "Battlements" then do
  239.         cornerline1 = "0 0"cr"3.3 0"cr"3.3 2.3"cr"2.3 2.3"cr"2.3 3.3"cr"0 3.3"cr"0 0"
  240.         sideline1 = "0 6"cr"1 6"cr"1 0"cr"3 0"cr"3 6"cr"4 6"
  241.         sideheight = 6
  242.         sidewidth = 4
  243.         sideXoffset = 0
  244.         sideYoffset = 0
  245.         cornerheight = 4
  246.         cornerwidth = 4
  247.         cornerXoffset = 0
  248.         cornerYoffset = 0
  249.         lines = 1
  250.         end
  251.  
  252.     when chosen = "Greek Key" then do
  253.         sideline1 = "0 0"cr"6 0"cr"6 5"cr"3 5"cr"3 3"cr"2 3"cr"2 6"cr"7 6"cr"7 0"cr"8 0"
  254.         sideline2 = "0 1"cr"5 1"cr"5 4"cr"4 4"cr"4 2"cr"1 2"cr"1 7"cr"8 7"cr"8 1"
  255.         sideheight = 8
  256.         sidewidth = 8
  257.         sideXoffset = 0
  258.         sideYoffset = 0
  259.         cornerheight = 8
  260.         cornerwidth = 8
  261.         cornerXoffset = 0
  262.         cornerYoffset = 0
  263.         Cornerline1 = "0 8"cr"0 0"cr"6 0"cr"6 5"cr"2 5"cr"2 2"cr"4 2"cr"4 3"cr"3 3"cr"3 4"cr"5 4"cr"5 1"cr"1 1"cr"1 6"cr"7 6"cr"7 0"cr"8 0"
  264.         Cornerline2 = "1 8"cr"1 7"cr"8 7"cr"8 1"
  265.         lines = 0
  266.         end
  267.  
  268.     when chosen = "Two Rules" then do
  269.         sideline1 = ""
  270.         sideline2 = ""
  271.         Cornerline1 = ""
  272.         cornerline2 = ""
  273.         lines = 2
  274.         end
  275.  
  276.     when chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  277.         sideline1 = ""
  278.         sideline2 = ""
  279.         Cornerline1 = ""
  280.         cornerline2 = ""
  281.         lines = 100    /* impossible number as a flag */
  282.         end
  283.  
  284.     when chosen = "Three Rules" then do
  285.         sideline1 = ""
  286.         sideline2 = ""
  287.         Cornerline1 = ""
  288.         cornerline2 = ""
  289.         lines = 3
  290.         end
  291.  
  292.     otherwise do
  293.         cornerline1 = "" 
  294.         cornerline2 = ""
  295.         cornerline3 = ""
  296.         sideline1 = ""
  297.         sideline2 = ""
  298.         sideline3 = ""
  299.         end
  300.     end
  301.  
  302.  
  303. /* Collect line weights from user  */
  304.  
  305. if lines>3  & lines~=100 then lines = 3
  306.  
  307. select
  308.     when lines = 0 then do
  309.         form = ppm_GetForm("Set sizes",8,"Border width ("units")")
  310.         if form = "" then exit_msg("Aborted by user")
  311.         cornerweight1 = ""
  312.         parse var form breadth 
  313.         end
  314.  
  315.     when lines = 1 then do
  316.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line weight (points)")
  317.         if form = "" then exit_msg("Aborted by user")
  318.         parse var form breadth "0a"x cornerweight1
  319.         end
  320.  
  321.     when lines = 2 then do
  322.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)")
  323.         if form = "" then exit_msg("Aborted by user")
  324.         parse var form breadth "0a"x cornerweight1 "0a"x cornerweight2
  325.         end
  326.  
  327.     when lines = 3 then do
  328.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Line 3 (points)")
  329.         if form = "" then exit_msg("Aborted by user")
  330.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerweight3
  331.         end
  332.  
  333.     when lines = 100 then do
  334.         form = ppm_GetForm("Set sizes",8,"Border width ("units")"cr"Line 1 (points)"cr"Line 2 (points)"cr"Corner Radius ("units")")
  335.         if form = "" then exit_msg("Aborted by user")
  336.         parse var form  breadth "0a"x cornerweight1 "0a"x cornerweight2 "0a"x cornerRadius
  337.         if cornerRadius = "" then cornerRadius = breadth*2
  338.         end
  339.  
  340.     otherwise nop
  341.     end
  342.  
  343.  
  344. if breadth="" then exit_msg("Aborted by User")
  345. breadth = breadth/mul /* mm to cm */
  346. if breadth>(word(mainsize,1))/2 | breadth>(word(mainsize,2))/2 then exit_msg("Too big")
  347.  
  348. defaultweight = (breadth*mul2)/20
  349. if cornerweight1 = "" then cornerweight1 = defaultweight
  350. if cornerweight2 = "" then cornerweight2 = defaultweight
  351. if cornerweight3 = "" then cornerweight3 = defaultweight
  352.  
  353. if lines = 1 | lines = 0 then do
  354.     cornerweight2 = cornerweight1
  355.     cornerweight3 = cornerweight1
  356.     end
  357. if lines = 2 then cornerweight3 = cornerweight2
  358. sideweight1 = cornerweight1
  359. sideweight2 = cornerweight2
  360. sideweight3 = cornerweight3
  361. maxweight = max(cornerweight1, cornerweight2, cornerweight3)
  362. maxwt = maxweight/72  /* max. line weight in inches  */
  363. if CurrentUnits = 2 then maxwt = maxwt*2.54  /* or centimetres  */
  364.  
  365.  
  366. /* First deal with plain rectangular borders  */
  367.  
  368. if chosen = "Two Rules" then do
  369.         call ppm_NewGroup()
  370.         call ppm_SetLineWeight(sideweight1)
  371.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  372.         call ppm_AddToGroup(rect1)
  373.         call ppm_SetLineWeight(sideweight2)
  374.         rect2 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  375.         call ppm_AddToGroup(rect2)
  376.         borderbox = ppm_MergeGroup()
  377.         call ppm_SetBoxAngle(borderbox,mainangle)
  378.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  379. /* Set an arbitrary margin in main box  */
  380.         margin = breadth*2
  381.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  382.         exit_msg("Done")
  383.         end
  384.  
  385. if chosen = "Two Rules Rounded" | chosen = "Two Rules Reverse Rounded" then do
  386.         rev = 0
  387.         if chosen = "Two Rules Reverse Rounded" then rev = 1
  388.         call ppm_ShowStatus("  Calculating outer line ...")
  389.         call ppm_NewGroup()
  390. trace n
  391. cornerRadius = cornerRadius/mul /* convert units */
  392. cRadius = cornerRadius /* for positioning centres of arcs */
  393.  
  394. AA=6.2831853/360    /* 2pi divided by 360 */
  395. AAA=AA*3
  396. angle= 180*AA /* convert to radians  */
  397. if rev = 1 then do /* for reverse curve corners  */
  398.     angle = 90*AA
  399.     AAA=-AAA  /* anti-clockwise arcs  */
  400.     cRadius = 0
  401.     end
  402.  
  403. drawstring = mainXpos (mainYpos+cornerRadius)||"0a"x
  404.  
  405. /* Draw the outer line, using 3 degree steps to give a smooth curve */
  406.         call ppm_SetLineWeight(sideweight1)
  407.         Xcentre = mainXpos+cRadius  /* centre of corner arc  */
  408.         Ycentre = mainYpos+cRadius
  409.         do i = 1 to 30
  410.             X2=Xcentre+(cornerRadius*cos(angle))
  411.             Y2=Ycentre+(cornerRadius*sin(angle))
  412.             angle=angle+AAA
  413.             drawstring=drawstring||X2 Y2"0a"x
  414.             end
  415.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) mainYpos"0a"x
  416.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) mainYpos"0a"x
  417.         Xcentre = mainXpos+mainwidth-cRadius
  418.         Ycentre = mainYpos+cRadius
  419.         if rev = 1 then angle = angle+(60*AAA)
  420.         do i = 1 to 30
  421.             X2=Xcentre+(cornerRadius*cos(angle))
  422.             Y2=Ycentre+(cornerRadius*sin(angle))
  423.             angle=angle+AAA
  424.             drawstring=drawstring||X2 Y2"0a"x
  425.             end
  426.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth) (mainYpos+cornerRadius)"0a"x
  427.         drawstring = drawstring||(mainXpos+mainwidth) (mainYpos+mainheight-cornerRadius)"0a"x
  428.  
  429.         Xcentre = mainXpos+mainwidth-cRadius
  430.         Ycentre = mainYpos+mainheight-cRadius
  431.         if rev = 1 then angle = angle+(60*AAA)
  432.         do i = 1 to 30
  433.             X2=Xcentre+(cornerRadius*cos(angle))
  434.             Y2=Ycentre+(cornerRadius*sin(angle))
  435.             angle=angle+AAA
  436.             drawstring=drawstring||X2 Y2"0a"x
  437.             end
  438.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight)"0a"x
  439.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight)"0a"x
  440.         Xcentre = mainXpos+cRadius
  441.         Ycentre = mainYpos+mainheight-cRadius
  442.         if rev = 1 then angle = angle+(60*AAA)
  443.         do i = 1 to 30
  444.             X2=Xcentre+(cornerRadius*cos(angle))
  445.             Y2=Ycentre+(cornerRadius*sin(angle))
  446.             angle=angle+AAA
  447.             drawstring=drawstring||X2 Y2"0a"x
  448.             end
  449.         if rev = 1 then drawstring = drawstring||mainXpos (mainYpos+mainheight-cornerRadius)"0a"x
  450.         drawstring = drawstring||mainXpos (mainYpos+cornerRadius)"0a"x
  451.         call ppm_SaveText("ram:arcdata",drawstring)
  452.         box = ppm_DrawPoly("ram:arcdata",boxname)
  453.         call ppm_AddToGroup(box)
  454.  
  455. trace n
  456. /* Draw the inner arc, in 3 degree steps to give a smooth curve */
  457.         call ppm_ShowStatus("  Calculating inner line ...")
  458.         call ppm_SetLineWeight(sideweight2)
  459.         cornerRadius2 = cornerRadius-breadth
  460.         if rev = 1 then do
  461.             cornerRadius2 = cornerRadius+breadth
  462.             cornerRadius = cornerRadius+breadth
  463.             a2 = sin(90*AA)/cornerRadius*breadth
  464.             a2 = atan(a2/sqrt(-a2*a2+1))
  465.             a3 = 3.1415927-(90*AA)-a2
  466.             startangle = a2
  467.             arcangle = (90*AA)-(2*startangle)
  468.             AAA = -(arcangle/30)
  469.             angle = (90*AA)-startangle
  470.             end
  471. trace n
  472. /* first corner */
  473.         drawstring = (mainXpos+breadth) (mainYpos+cornerRadius)||"0a"x
  474.         Xcentre = mainXpos+cRadius
  475.         Ycentre = mainYpos+cRadius
  476.         do i = 0 to 30
  477.             X2=Xcentre+(cornerRadius2*cos(angle))
  478.             Y2=Ycentre+(cornerRadius2*sin(angle))
  479.             angle=angle+AAA
  480.             drawstring=drawstring||X2 Y2"0a"x
  481.             end
  482.         if rev = 1 then drawstring = drawstring||(mainXpos +cornerRadius) (mainYpos+breadth)"0a"x
  483.         drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+breadth)"0a"x
  484.  
  485. /* second corner */
  486.         Xcentre = mainXpos+mainwidth-cRadius
  487.         Ycentre = mainYpos+cRadius
  488.         if rev = 1 then angle = (180*AA)-startangle
  489.         do i = 0 to 30
  490.             X2=Xcentre+(cornerRadius2*cos(angle))
  491.             Y2=Ycentre+(cornerRadius2*sin(angle))
  492.             angle=angle+AAA
  493.             drawstring=drawstring||X2 Y2"0a"x
  494.             end
  495.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -breadth) (mainYpos+cornerRadius)"0a"x
  496.         drawstring = drawstring||(mainXpos+mainwidth-breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  497.  
  498. /* third corner  */
  499.         Xcentre = mainXpos+mainwidth-cRadius
  500.         Ycentre = mainYpos+mainheight-cRadius
  501.         if rev = 1 then angle = (270*AA)-startangle
  502.         do i = 0 to 30
  503.             X2=Xcentre+(cornerRadius2*cos(angle))
  504.             Y2=Ycentre+(cornerRadius2*sin(angle))
  505.             angle=angle+AAA
  506.             drawstring=drawstring||X2 Y2"0a"x
  507.             end
  508.         if rev = 1 then drawstring = drawstring||(mainXpos +mainwidth -cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  509.         drawstring = drawstring||(mainXpos+cornerRadius) (mainYpos+mainheight-breadth)"0a"x
  510.  
  511. /* fourth corner  */
  512.         Xcentre = mainXpos+cRadius
  513.         Ycentre = mainYpos+mainheight-cRadius
  514.         if rev = 1 then angle = 0-startangle
  515.         do i = 0 to 30
  516.             X2=Xcentre+(cornerRadius2*cos(angle))
  517.             Y2=Ycentre+(cornerRadius2*sin(angle))
  518.             angle=angle+AAA
  519.             drawstring=drawstring||X2 Y2"0a"x
  520.             end
  521.         if rev = 1 then drawstring = drawstring||(mainXpos +breadth) (mainYpos+mainheight-cornerRadius)"0a"x
  522.         drawstring = drawstring||(mainXpos+breadth) (mainYpos+cornerRadius)"0a"x
  523.         call ppm_SaveText("ram:arcdata2",drawstring)
  524.         box = ppm_DrawPoly("ram:arcdata2",boxname)
  525.         call ppm_AddToGroup(box)
  526.         borderbox = ppm_MergeGroup()
  527.         call ppm_SetBoxAngle(borderbox,mainangle)
  528.         call ppm_SetBoxPosition(borderbox,mainXpos-((sideweight1/2)/mul2), mainYpos-((sideweight1/2)/mul2))  
  529.  
  530.  
  531. /* Set an arbitrary margin in main box  */
  532.         margin = cornerRadius*1.2
  533.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  534.         exit_msg()
  535.         end
  536.  
  537.  
  538. if chosen = "Three Rules" then do
  539.         call ppm_NewGroup()
  540.         call ppm_SetLineWeight(sideweight1)
  541.         rect1 = ppm_DrawRect(mainXpos, mainYpos, mainXpos+word(mainsize,1), mainYpos+word(mainsize,2))
  542.         call ppm_AddToGroup(rect1)
  543.         call ppm_SetLineWeight(sideweight2)
  544.         rect2 = ppm_DrawRect(mainXpos+(breadth/3), mainYpos+(breadth/3), mainXpos+word(mainsize,1)-(breadth/3), mainYpos+word(mainsize,2)-(breadth/3))
  545.         call ppm_AddToGroup(rect2)
  546.         call ppm_SetLineWeight(sideweight3)
  547.         rect3 = ppm_DrawRect(mainXpos+breadth, mainYpos+breadth, mainXpos+word(mainsize,1)-breadth, mainYpos+word(mainsize,2)-breadth)
  548.         call ppm_AddToGroup(rect3)
  549.         borderbox = ppm_MergeGroup()
  550.         call ppm_SetBoxAngle(borderbox,mainangle)
  551.         call ppm_SetBoxPosition(borderbox,mainXpos,mainYpos)
  552. /* Set an arbitrary margin in main box  */
  553.         margin = breadth*2
  554.         call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  555.         exit_msg("Done")
  556.         end
  557.  
  558.  
  559. /* Now deal with borders using shapes scaled to fit  */
  560.  
  561. mainheight = (word(mainsize, 2))-(breadth*2)
  562. mainwidth = (word(mainsize, 1))-(breadth*2)
  563.  
  564. call ppm_NewGroup()
  565. count = 0
  566.  
  567. if cornerline1 ~= "" then do
  568.     drawstring = cornerline1
  569.     call ppm_SaveText("ram:linedata",drawstring)
  570.     call ppm_SetLineWeight(cornerweight1)
  571.     call ppm_SetFillPattern(cornerfill1)
  572.     cornerbox = ppm_DrawPoly("ram:linedata")
  573.     call ppm_AddToGroup(cornerbox)
  574.     count = count+1
  575.     end
  576.  
  577. if cornerline2 ~= "" then do
  578.     drawstring = cornerline2
  579.     call ppm_SaveText("ram:linedata",drawstring)
  580.     call ppm_SetLineWeight(cornerweight2)
  581.     call ppm_SetFillPattern(cornerfill2)
  582.     cornerbox = ppm_DrawPoly("ram:linedata")
  583.     call ppm_AddToGroup(cornerbox)
  584.     count = count+1
  585.     end
  586.  
  587. if cornerline3 ~= "" then do
  588.     drawstring = cornerline3
  589.     call ppm_SaveText("ram:linedata",drawstring)
  590.     call ppm_SetLineWeight(cornerweight3)
  591.     call ppm_SetFillPattern(cornerfill3)
  592.     cornerbox = ppm_DrawPoly("ram:linedata")
  593.     call ppm_AddToGroup(cornerbox)
  594.     count = count+1
  595.     end
  596.  
  597. if count>1 then cornerbox = ppm_MergeGroup() /* Merge fails with 1 box */
  598.  
  599. if cornerbox ~=0 then do
  600.     if cornerheight~=0 & cornerwidth~=0 then call ppm_SetBoxSize(cornerbox, cornerwidth, cornerheight)
  601.     call ppm_SetBoxOffset(cornerbox,cornerXoffset,cornerYoffset)
  602.     csize = ppm_GetBoxSize(cornerbox)
  603.     cXsize = word(csize, 1)
  604.     cYsize = word(csize, 2)
  605.     cscale = ppm_GetBoxScale(cornerbox)
  606.     cscaleX = word(cscale, 1)
  607.     cscaleY = word(cscale, 2)
  608.     cangle = ppm_GetBoxAngle(cornerbox)
  609.     end
  610.  
  611.  
  612. call ppm_NewGroup()
  613. count = 0
  614.  
  615. if sideline1 ~= "" then do
  616.     drawstring = sideline1
  617.     call ppm_SaveText("ram:linedata",drawstring)
  618.     call ppm_SetLineWeight(sideweight1)
  619.     call ppm_SetFillPattern(sidefill1)
  620.     sidebox = ppm_DrawPoly("ram:linedata")
  621.     call ppm_AddToGroup(sidebox)
  622.     count = count+1
  623.     end
  624.  
  625. if sideline2 ~= "" then do
  626.     drawstring = sideline2
  627.     call ppm_SaveText("ram:linedata",drawstring)
  628.     call ppm_SetLineWeight(sideweight2)
  629.     call ppm_SetFillPattern(sidefill2)
  630.     sidebox = ppm_DrawPoly("ram:linedata")
  631.     call ppm_AddToGroup(sidebox)
  632.     count = count+1
  633.     end
  634.  
  635. if sideline3 ~= "" then do
  636.     drawstring = sideline3
  637.     call ppm_SaveText("ram:linedata",drawstring)
  638.     call ppm_SetLineWeight(sideweight3)
  639.     call ppm_SetFillPattern(sidefill3)
  640.     sidebox = ppm_DrawPoly("ram:linedata")
  641.     call ppm_AddToGroup(sidebox)
  642.     count = count+1
  643.     end
  644.  
  645. if count>1 then sidebox = ppm_MergeGroup()
  646.  
  647.  
  648. /* Place Corner Units */
  649. call ppm_NewGroup()
  650. call ppm_ShowStatus("Placing Corner Units")
  651. if cornerbox ~=0 then do
  652.     cbox = ppm_CloneBox(cornerbox, 0, 0)
  653.     call ppm_AddToGroup(cbox)
  654.     call ppm_SetBoxAngle(cbox,0)
  655.     call ppm_SetBoxSize(cbox, breadth, breadth)
  656.     call ppm_SetBoxScale(cbox, cscaleX*breadth/cXsize, cscaleY*breadth/cYsize)
  657.     call ppm_SetBoxPosition(cbox, mainXpos, mainYpos)
  658.     cbox2 = ppm_CloneBox(cbox, 0, 0)
  659.     call ppm_AddToGroup(cbox2)
  660.     call ppm_SetBoxPosition(cbox2, mainXpos, mainYpos+mainheight+breadth)
  661.     call ppm_SetBoxAngle(cbox2, (cangle+90)//360)
  662.     cbox3 = ppm_CloneBox(cbox, 0, 0)
  663.     call ppm_AddToGroup(cbox3)
  664.     call ppm_SetBoxPosition(cbox3, mainXpos+mainwidth+breadth, mainYpos+mainheight+breadth)
  665.     call ppm_SetBoxAngle(cbox3, (cangle+180)//360)
  666.     cbox4 = ppm_CloneBox(cbox, 0, 0)
  667.     call ppm_AddToGroup(cbox4)
  668.     call ppm_SetBoxPosition(cbox4, mainXpos+mainwidth+breadth, mainYpos)
  669.     call ppm_SetBoxAngle(cbox4, (cangle+270)//360)
  670.     call ppm_SetBoxAngle(cbox, cangle)
  671.     end
  672.  
  673.  
  674. if sidebox = 0 then exit_msg("Done")
  675.  
  676.  
  677. /* Collect original size and graphic scale of box */
  678.     if sideheight~=0 & sidewidth~=0 then call ppm_SetBoxSize(sidebox, sidewidth, sideheight)
  679.     call ppm_SetBoxOffset(sidebox,sideXoffset,sideYoffset)
  680.     scaleX = word(ppm_GetBoxScale(sidebox), 1)
  681.     scaleY = word(ppm_GetBoxScale(sidebox), 2)
  682.     width = word(ppm_GetBoxSize(sidebox), 1)
  683.     height = word(ppm_GetBoxSize(sidebox), 2)
  684.     scale1 = breadth/height
  685.     width2 = width*scale1
  686. totalwidth = width2
  687.  
  688.  
  689. heightcount = mainheight%totalwidth /* Use integer division to get number of repeats */
  690. widthcount = mainwidth%totalwidth
  691. if widthcount = 0 | heightcount = 0 then do
  692.     gone = ppm_DeleteBox(sidebox)
  693.     gone = ppm_DeleteBox(cornerbox)
  694.     gone = ppm_DeleteBox(cbox)
  695.     gone = ppm_DeleteBox(cbox2)
  696.     gone = ppm_DeleteBox(cbox3)
  697.     gone = ppm_DeleteBox(cbox4)
  698.     exit_msg("Pattern too big")
  699.     end
  700.  
  701. Xtotalwidth = mainwidth/widthcount  /* Exact width of whole pattern */
  702. Ytotalwidth = mainheight/heightcount
  703. Xscale = Xtotalwidth/totalwidth
  704. Yscale = Ytotalwidth/totalwidth
  705.  
  706.  
  707. widthX = width2*Xscale
  708. widthY = width2*Yscale 
  709.  
  710.  
  711. /* Place top units  */
  712.  
  713. call ppm_ShowStatus("Placing Top Units")
  714. leftpos = mainXpos+breadth
  715. do j=1 to widthcount
  716.     newbox = ppm_CloneBox(sidebox, 0, 0)
  717.     call ppm_AddToGroup(newbox)
  718.     call ppm_SetBoxSize(newbox, widthX, breadth)
  719.     call ppm_SetBoxPosition(newbox, leftpos, mainYpos)
  720.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  721.     call ppm_SetBoxAngle(newbox, 0)
  722.     leftpos = leftpos+widthX
  723.     end
  724.  
  725. /* Place right side units */
  726. call ppm_ShowStatus("Placing Right Side Units")
  727. toppos = mainYpos+breadth
  728. leftpos = mainXpos+word(mainsize, 1)
  729.  
  730. do j=1 to heightcount
  731.     newbox = ppm_CloneBox(sidebox, 0, 0)
  732.     call ppm_AddToGroup(newbox)
  733.     call ppm_SetBoxAngle(newbox, 270)
  734.     call ppm_SetBoxSize(newbox, widthY, breadth)
  735.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  736.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  737.     toppos = toppos+widthY
  738.     end
  739.  
  740.  
  741. /* Place bottom units  */
  742.  
  743. call ppm_ShowStatus("Placing Bottom Units")
  744. leftpos = mainXpos+breadth+mainwidth
  745. toppos = mainYpos+word(mainsize, 2)
  746.  
  747. do j=1 to widthcount
  748.     newbox = ppm_CloneBox(sidebox, 0, 0)
  749.     call ppm_AddToGroup(newbox)
  750.     call ppm_SetBoxAngle(newbox, 180)
  751.     call ppm_SetBoxSize(newbox, widthX, breadth)
  752.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  753.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Xscale), (scaleY * abs(scale1)) )
  754.     leftpos = leftpos-widthX
  755.     end
  756.  
  757. /* Place left side units */
  758. call ppm_ShowStatus("Placing Left Side Units")
  759. toppos = mainYpos+breadth+mainheight
  760. leftpos = mainXpos
  761.  
  762. do j=1 to heightcount
  763.     newbox = ppm_CloneBox(sidebox, 0, 0)
  764.     call ppm_AddToGroup(newbox)
  765.     call ppm_SetBoxAngle(newbox, 90)
  766.     call ppm_SetBoxSize(newbox, widthY, breadth)
  767.     call ppm_SetBoxPosition(newbox, leftpos, toppos)
  768.     call ppm_SetBoxScale(newbox, (scaleX *scale1* Yscale), (scaleY * abs(scale1)) )
  769.     toppos = toppos-widthY
  770.     end 
  771.  
  772. /* Merge all the units into one box  */
  773. borderbox = ppm_MergeGroup()
  774. call ppm_SetBoxAngle(borderbox,mainangle)
  775.  
  776. /* resize box slightly so that thick lines are not cropped */
  777. bsize = ppm_GetBoxSize(borderbox)
  778. bwidth = word(bsize,1)
  779. bheight = word(bsize,2)
  780. call ppm_SetBoxSize(borderbox,bwidth+(maxwt*2),bheight+(maxwt*2))
  781. call ppm_SetBoxPosition(borderbox,mainXpos-maxwt,mainYpos-maxwt)
  782. call ppm_SetBoxOffset(borderbox,maxwt,maxwt)
  783.  
  784. /* Delete the pattern boxes  */
  785.  
  786.     gone = ppm_DeleteBox(cornerbox)
  787.     gone = ppm_DeleteBox(sidebox)   
  788.  
  789. /* Set an arbitrary margin in main box  */
  790. margin = breadth
  791. boxtype = upper(word(ppm_GetBoxInfo(mainbox),1))
  792. if boxtype = "TEXT" then margin = breadth*2
  793. call ppm_SetBoxMargins(mainbox, margin, margin, margin, margin)
  794. call ppm_BoxToFront(borderbox)
  795.  
  796. call exit_msg()
  797.  
  798. end
  799.  
  800. error:
  801. syntax:
  802.     do
  803.     exit_msg("Genie failed due to error: "errortext(rc))
  804.     end
  805.  
  806. break_d:
  807. break_e:
  808. break_c:
  809. halt:
  810. call exit_msg("Aborted by User")
  811.  
  812. exit_msg:
  813.     do
  814.     parse arg message
  815.     if message ~= "" then
  816.     call ppm_Inform(1, message,"Resume")
  817.     call ppm_ClearStatus()
  818.     call ppm_SetUnits(CurrentUnits)
  819.     call ppm_AutoUpdate(1)
  820.     exit
  821.     end
  822.  
  823.